import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../module_common/widgets/skeleton/dapp_tag_skeleton.dart';
import '../dapp_tag_item.dart';
import '../dapp_title.dart';

class DAppHeaderDelegate extends SliverPersistentHeaderDelegate {
  bool isLoading = true;

  final List<String> tagsLists = [
    "All",
    "Gamefi",
    "Defi",
    "ETH",
    "BSC",
    "Collectibles"
  ];
  @override
  Widget build(
    BuildContext context,
    double shrinkOffset,
    bool overlapsContent,
  ) {
    return Container(
      color: Color.fromRGBO(255, 255, 255, 1),
      child: Column(
        children: [
          DAppTitle(
            title: 'Dapps',
            showHotIcon: false,
            showMore: false,
            isLoading: isLoading,
          ),
          if (!isLoading && tagsLists.length > 0)
            Container(
              margin: const EdgeInsets.only(left: 20, top: 10, bottom: 10),
              padding: const EdgeInsets.only(top: 8, bottom: 2),
              height: 40.w,
              child: ListView.builder(
                  itemCount: tagsLists.length,
                  scrollDirection: Axis.horizontal,
                  itemBuilder: (BuildContext context, int index) {
                    return DAppTagItem(
                        onClick: () {
                        },
                        title: tagsLists[index],
                        isActive: index == 0);
                  }),
            ),
          if (isLoading)
            Column(
              children: [
                Container(
                  margin: const EdgeInsets.only(left: 20, top: 10, bottom: 10),
                  padding: const EdgeInsets.only(top: 8, bottom: 2),
                  height: 40.w,
                  child: ListView.builder(
                      itemCount: 6,
                      physics: NeverScrollableScrollPhysics(),
                      scrollDirection: Axis.horizontal,
                      itemBuilder: (BuildContext context, int index) {
                        return DAppTagSkeleton();
                      }),
                ),
              ],
            ),
        ],
      ),
    );
  }

  @override
  double get maxExtent => 100;

  @override
  double get minExtent => 100;

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    return false;
  }
}
